// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   UpdateImg.java

package include.right;

import include.nseer_db.nseer_db_backup;
import java.io.PrintStream;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;

public class UpdateImg
{

	private String cols[];
	private String ID;
	private String database;
	private String sql;
	private ResultSet rs;
	private ResultSet rs1;
	private ServletContext dbApplication;

	public UpdateImg(ServletContext dbApplication)
	{
		cols = new String[1000];
		ID = "";
		database = "";
		sql = "";
		rs = null;
		rs1 = null;
		this.dbApplication = dbApplication;
	}

	public void update(String unit_db_name, String ID, String dbase, String right[])
	{
		this.ID = ID;
		database = dbase;
		cols = right;
		nseer_db_backup db = new nseer_db_backup(dbApplication);
		nseer_db_backup db1 = new nseer_db_backup(dbApplication);
		try
		{
			if (db.conn(unit_db_name) && db1.conn(unit_db_name))
			{
				String ids = ",";
				String tree_view = (new StringBuilder(String.valueOf(database))).append("_view").toString();
				String tree = (new StringBuilder(String.valueOf(database))).append("_tree").toString();
				for (int i = 0; i < cols.length; i++)
					if (cols[i] != null)
						ids = (new StringBuilder(String.valueOf(ids))).append(cols[i]).append(",").toString();

				String sql1 = "";
				String sql2 = "";
				String module = "";
				String main = "";
				String secondary = "";
				String third = "";
				StringTokenizer tokenTO = null;
				sql = (new StringBuilder("select * from drag_img where human_ID='")).append(ID).append("' and tree_view_name='").append(tree_view).append("'").toString();
				for (rs = db.executeQuery(sql); rs.next();)
				{
					sql1 = "";
					tokenTO = new StringTokenizer(rs.getString("drag_text"), "--");
					int tokencount = tokenTO.countTokens();
					switch (tokencount)
					{
					case 2: // '\002'
						while (tokenTO.hasMoreTokens()) 
						{
							module = tokenTO.nextToken();
							main = tokenTO.nextToken();
						}
						sql1 = (new StringBuilder("select * from ")).append(tree).append(" where main='").append(main).append("'").toString();
						break;

					case 3: // '\003'
						while (tokenTO.hasMoreTokens()) 
						{
							module = tokenTO.nextToken();
							main = tokenTO.nextToken();
							secondary = tokenTO.nextToken();
						}
						sql1 = (new StringBuilder("select * from ")).append(tree).append(" where main='").append(main).append("' and secondary='").append(secondary).append("'").toString();
						break;

					case 4: // '\004'
						while (tokenTO.hasMoreTokens()) 
						{
							module = tokenTO.nextToken();
							main = tokenTO.nextToken();
							secondary = tokenTO.nextToken();
							third = tokenTO.nextToken();
						}
						sql1 = (new StringBuilder("select * from ")).append(tree).append(" where main='").append(main).append("' and secondary='").append(secondary).append("' and third='").append(third).append("'").toString();
						break;
					}
					if (!sql1.equals(""))
					{
						rs1 = db1.executeQuery(sql1);
						if (rs1.next() && ids.indexOf((new StringBuilder(",")).append(rs1.getString("id")).append(",").toString()) == -1)
						{
							sql2 = (new StringBuilder("delete from drag_img where id='")).append(rs.getString("id")).append("'").toString();
							db1.executeUpdate(sql2);
						}
					}
				}

			} else
			{
				System.out.println("i am sorry");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		db.close();
		db1.close();
	}
}
